#ifndef __USART_485_H
#define __USART_485_H

#include <stdint.h>
#include "at32f403a_407_board.h"
#include "los_task.h"


#define USART6_RX_BUF_SIZE  256
#define USART6_TX_BUF_SIZE  256
#define ECHO_ENABLED 1 

typedef struct {
    uint8_t buf[USART6_RX_BUF_SIZE];
    uint16_t head;
    uint16_t tail;
    uint16_t count;
} usart6_rx_buf_t;

typedef struct {
    uint8_t buf[USART6_TX_BUF_SIZE];
    volatile uint16_t head;
    volatile uint16_t tail;
    volatile uint16_t count;
} usart6_tx_buf_t;


void usart6_send_data_it(uint8_t *data, uint16_t len);
void usart6_init(uint32_t baudrate);
uint16_t usart6_get_rx_data_len(void);
uint16_t usart6_read_rx_data(uint8_t *buf, uint16_t len);
void usart6_clear_rx_buffer(void);

void usart6_echo_handler(void);
u8 get_usart6_handler(u8* rx_data);


#endif